<template>
  <div class="mod-config">
    <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
    >
      <el-form-item label="分类名">
        <el-input
            v-model="dataForm.susName"
            placeholder="分类名"
            clearable
        >
        </el-input>
      </el-form-item>
      <el-form-item label="用户性别">
        <el-select
            v-model="dataForm.suSex"
            placeholder="用户性别"
            clearable
        >
          <el-option
              v-for="item in sexOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="用户最小年龄">
        <el-input
            type="number"
            oninput ="value=value.replace(/[^\d]/g,'')"
            v-model.number="dataForm.suAgeMin"
            placeholder="用户最小年龄"
            :min="0"
        ></el-input>
      </el-form-item>
      <el-form-item label="用户最大年龄">
        <el-input
            type="number"
            oninput ="value=value.replace(/[^\d]/g,'')"
            v-model.number="dataForm.suAgeMax"
            placeholder="用户最大年龄"
            :min="0"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%"
    >
      <el-table-column
          prop="susName"
          header-align="center"
          align="center"
          label="分类名"
      >
      </el-table-column>
      <el-table-column
          prop="suCode"
          header-align="center"
          align="center"
          label="用户登录名"
      >
      </el-table-column>
      <el-table-column
          prop="suName"
          header-align="center"
          align="center"
          label="用户姓名"
      >
      </el-table-column>
      <el-table-column
          prop="suSex"
          header-align="center"
          align="center"
          label="性别"
      >
        <template #default="scope">
          <span v-if="scope.row.suSex == 1 ">男</span>
          <span v-else-if="scope.row.suSex == 0">未知</span>
          <span v-else-if="scope.row.suSex == 2">女</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="suAge"
          header-align="center"
          align="center"
          label="年龄"
      >
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->

  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      sexOptions: [
        {
          value: "0",
          label: "未知",
        },
        {
          value: "1",
          label: "男",
        },
        {
          value: "2",
          label: "女",
        },
      ],
      dataForm: {
        susName: "",
        suCode: "",
        suName: "",
        suSex: "",
        suAgeMin: undefined,
        suAgeMax: undefined,
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
    };
  },
  created() {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      axios({
        method: "get",
        url: "/sysUser/list",
        params: {
          page: this.pageIndex,
          limit: this.pageSize,
          susName: this.dataForm.susName,
          suSex: this.dataForm.suSex,
          suAgeMin: this.dataForm.suAgeMin,
          suAgeMax: this.dataForm.suAgeMax,
        }
      }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataList = data.page.list;
              this.totalPage = data.page.totalCount;
            } else {
              this.dataList = [];
              this.totalPage = 0;
            }
            this.dataListLoading = false;
          }
      )
    },

    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },

  },
};
</script>
